/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sgep.actions;

import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import java.util.List;
import org.apache.struts2.components.File;
import sgep.po.Application;
import sgep.services.ApplicationService;

/**
 *
 * @author mg
 */
public class ApplicationEdit extends ActionSupport {

    private String appid;
    private Application app;
    private List<String> paralls;
    private String exports = "";
    private File fileupload;
    private String option;

    public String getOption() {
        return option;
    }

    public void setOption(String option) {
        this.option = option;
    }

    public File getFileupload() {
        return fileupload;
    }

    public void setFileupload(File fileupload) {
        this.fileupload = fileupload;
    }

    public String getExports() {
        return exports;
    }

    public void setExports(String exports) {
        this.exports = exports;
    }

    public List<String> getParalls() {
        return paralls;
    }

    public void setParalls(List<String> paralls) {
        this.paralls = paralls;
    }
    private ApplicationService appService;

    public void setAppService(ApplicationService appService) {
        this.appService = appService;
    }

    public Application getApp() {
        return app;
    }

    public void setApp(Application app) {
        this.app = app;
    }

    public String getAppid() {
        return appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    @Override
    public String execute() throws Exception {
        //System.out.println("appid:" + appid);
        paralls = new ArrayList<String>();
        paralls.add("no");
        paralls.add("mpi");
        paralls.add("smp");
//        if (option != null && option.equals("new")) {
            app = new Application();
            app.setId(appid);
            app.setApp(appid);
            app.setParallel("no");
            app.setXApp("no");
            List e = new ArrayList();
            e.add("user1");
            e.add("user2");
            app.setExport(e);

            //app = appService.getApplication(id);
            List exs = app.getExport();
            for (Object s : exs) {
                exports += (String) s + "\n";
            }
//        } else if (option != null && option.equals("edit")) {
//            System.out.println(app.getId());
//            System.out.println(app.getApp());
//            System.out.println(app.getBinary());
//            System.out.println(app.getNamef());
//        }
        return "success";
    }

    public String save() throws Exception {
        System.out.println(app.getId());
        System.out.println(app.getApp());
        System.out.println(app.getBinary());
        System.out.println(app.getNamef());
        return "save";
    }

    public String delete() throws Exception {
        return "delete";
    }
}
